/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
package de.thwildau.tm.moses.thrift.ui.preferences.pages.general;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbenchPropertyPage;

import de.thwildau.tm.moses.thrift.ui.Activator;
import de.thwildau.tm.moses.thrift.ui.preferences.PreferencesConstants;
 

/**
 * The Implementation of the General PreferencePage of the Thrift Plugin. It allows to configure the path to the Thrift Compiler
 * and to enable/disable to autoCompile setting. 
 *
 * @author Thomas Kistel
 * @version $Revision: 756 $
 */
public class GeneralPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage,
        IWorkbenchPropertyPage {
    
    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
     */
    @Override
    public IAdaptable getElement() {
        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
     */
    @Override
    public void setElement(IAdaptable element) {
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
     */
    @Override
    public void init(IWorkbench workbench) {
        setDescription("The general settings of Thrift Workbench.");
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
     */
    @Override
    protected void createFieldEditors() {
        BooleanFieldEditor autoCompile = new BooleanFieldEditor(PreferencesConstants.PREF_KEY_AUTO_COMPILE, "Compile Thrift files on Save", getFieldEditorParent());
        FileFieldEditor thriftCompiler = new FileFieldEditor(PreferencesConstants.PREF_KEY_COMPILER_PATH, "Path of the Thrift Compiler executable.", getFieldEditorParent());
        thriftCompiler.setFileExtensions(new String[] {"*.exe"});
        addField(autoCompile);
        addField(thriftCompiler);
        
    }
    
    protected IPreferenceStore doGetPreferenceStore() {
        return Activator.getInstance().getPreferenceStore();
    }
    
    public boolean performOk() {
        return super.performOk();
    }
}
